home *** CD-ROM | disk | FTP | other *** search
- /*-------------------------------------
- #
- # MultiFinder-Aware Simple Application
- # to modify Print Dialogs
- #
- # NoDraft
- #
- # NoDraft.c - C Source
- #
- # NoDraft is an example application that
- # demonstrates how to modify Print Dialogs.
- #
- ------------------------------------------*/
-
- #include <Values.h>
- #include <Types.h>
- #include <Resources.h>
- #include <QuickDraw.h>
- #include <Fonts.h>
- #include <Events.h>
- #include <Windows.h>
- #include <Menus.h>
- #include <TextEdit.h>
- #include <Desk.h>
- #include <ToolUtils.h>
- #include <Memory.h>
- #include <SegLoad.h>
- #include <OSUtils.h>
- #include <OSEvents.h>
- #include <DiskInit.h>
- #include <Packages.h>
- #include <Printing.h>
- #include <Traps.h>
- #include <NoDraft.h>
- #include <NoDraft_types.h>
-
- WindowPtr myWindow;
-
- SysEnvRec gMac;
- Boolean gHasWaitNextEvent;
- Boolean gInBackground;
-
- void EventLoop( void );
- void DoEvent( EventRecord *event );
- void DoUpdate( WindowPtr window );
- void DoActivate( WindowPtr window, Boolean becomingActive );
- void DrawWindow( WindowPtr window );
- void AdjustMenus( void );
- void DoMenuCommand( long menuResult );
- void Initialize( void );
- Boolean IsAppWindow( WindowPtr window );
- Boolean IsDAWindow( WindowPtr window );
- Boolean TrapAvailable( short tNumber, TrapType tType );
- void AlertUser( short error );
-
- void ShowAboutMeDialog(void) extern; /* my about… dialog */
- OSErr DoPrintDialog() extern;
-
- extern void _DataInit();
-
- #pragma segment Main
- main()
- {
- UnloadSeg((Ptr) _DataInit);
- MaxApplZone();
- Initialize();
- UnloadSeg((Ptr) Initialize);
- EventLoop();
- }
-
- void EventLoop()
- {
- RgnHandle cursorRgn;
- Boolean gotEvent;
- EventRecord event;
-
- cursorRgn = NewRgn();
- do {
- /* use WNE if it is available */
- if ( gHasWaitNextEvent ) {
- SetCursor(&qd.arrow);
- gotEvent = WaitNextEvent(everyEvent, &event, MAXLONG, cursorRgn);
- }
- else {
- SystemTask();
- gotEvent = GetNextEvent(everyEvent, &event);
- }
- if ( gotEvent ) {
- /* we just need the arrow cursor */
- SetCursor(&qd.arrow);
- DoEvent(&event);
- }
- } while ( true ); /* quit via ExitToShell() */
- } /*EventLoop*/
-
- void DoEvent(event)
- EventRecord *event;
- {
- short part;
- WindowPtr window;
-
- switch ( event->what ) {
- case mouseDown:
- part = FindWindow(event->where, &window);
- switch ( part ) {
- case inMenuBar:
- AdjustMenus();
- DoMenuCommand(MenuSelect(event->where));
- break;
- case inSysWindow:
- SystemClick(event, window);
- break;
- }
- break;
- case activateEvt:
- DoActivate((WindowPtr) event->message, (event->modifiers & activeFlag) != 0);
- break;
- case updateEvt:
- DoUpdate((WindowPtr) event->message);
- break;
- case kOSEvent:
- switch ((event->message >> 24) & 0x0FF) {
- case kSuspendResumeMessage:
- gInBackground = (event->message & kResumeMask) == 0;
- DoActivate(FrontWindow(), !gInBackground);
- break;
- }
- break;
- }
- } /*DoEvent*/
-
- void DoUpdate(window)
- WindowPtr window;
- {
- if ( IsAppWindow(window) ) {
- BeginUpdate(window);
- if ( ! EmptyRgn(window->visRgn) )
- DrawWindow(window);
- EndUpdate(window);
- }
- } /*DoUpdate*/
-
- void DoActivate(window, becomingActive)
- WindowPtr window;
- Boolean becomingActive;
- {
- Boolean ismine;
-
- ismine = (window == myWindow) ? true : false;
- if ( IsAppWindow(window) ) {
- if ( becomingActive )
- {
- SetPort(window);
- DrawMenuBar();
- }
- } /* of isappwindow */
- } /*DoActivate*/
-
- void DrawWindow(window)
- WindowPtr window;
- {
-
- SetPort(window);
- EraseRect(&window->portRect);
- SetOrigin(0, 0);
- DrawGrowIcon(window);
-
- } /*DrawWindow*/
-
- void AdjustMenus()
- {
- WindowPtr window;
- MenuHandle menu;
-
- window = FrontWindow();
-
- menu = GetMHandle(mFile);
- if ( IsDAWindow(window) )
- {
- EnableItem(menu, iClose);
- /* but no printing */
- DisableItem(menu, iPSetUp);
- DisableItem(menu, iPrint);
- }
- else
- {
- DisableItem(menu, iClose);
- DisableItem(menu, iPSetUp);
- EnableItem(menu, iPrint);
- }
-
- } /*AdjustMenus*/
-
- void DoMenuCommand(menuResult)
- long menuResult;
- {
- short menuID;
- short menuItem;
- Str255 daName;
- short daRefNum;
- Boolean handledByDA;
-
- menuID = HiWord(menuResult);
- menuItem = LoWord(menuResult);
- switch ( menuID ) {
- case mApple:
- switch ( menuItem ) {
- case iAbout: /* alert for About */
- /* do filtered dialog */
- ShowAboutMeDialog();
- break;
- default:
- GetItem(GetMHandle(mApple), menuItem, daName);
- daRefNum = OpenDeskAcc(daName);
- break;
- }
- break;
- case mFile:
- switch ( menuItem ) {
- case iPrint:
- /* do Print job dialog */
- /* the Draft Mode is disabled */
- /* and a filter is added */
- PrOpen();
- DoPrintDialog();
- PrClose();
- break;
- case iQuit:
- ExitToShell();
- break;
- }
- break;
- case mEdit:
- handledByDA = SystemEdit(menuItem-1);
- break;
- }
- HiliteMenu(0);
- } /*DoMenuCommand*/
-
- #pragma segment Initialize
- void Initialize()
- {
- Handle menuBar;
- long total, contig;
- EventRecord event;
- short count;
- Boolean good;
-
- gInBackground = false;
- InitGraf((Ptr) &qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
- for (count = 1; count <= 3; count++)
- EventAvail(everyEvent, &event);
- SysEnvirons(kSysEnvironsVersion, &gMac);
- if (gMac.machineType < 0) AlertUser(eUnknown);
- gHasWaitNextEvent = TrapAvailable(_WaitNextEvent, ToolTrap);
- if ((long) GetApplLimit() - (long) ApplicZone() < kMinHeap) AlertUser(eUnknown);
- PurgeSpace(&total, &contig);
- if (total < kMinSpace) AlertUser(eUnknown);
- good = false;
- myWindow = GetNewWindow(rWindow, nil, (WindowPtr) -1);
- good = myWindow != nil;
- if ( good ) {
- SetPort(myWindow);
- ShowWindow(myWindow);
- } else {
- AlertUser(eNoWindow);
- ExitToShell();
- }
- menuBar = GetNewMBar(rMenuBar);
- if ( menuBar == nil ) AlertUser(eUnknown);
- SetMenuBar(menuBar);
- DisposHandle(menuBar);
- AddResMenu(GetMHandle(mApple), 'DRVR');
- DrawMenuBar();
-
- } /*Initialize*/
-
- #pragma segment Main
- Boolean IsAppWindow(window)
- WindowPtr window;
- {
- short windowKind;
-
- if ( window == nil )
- return false;
- else {
- /* app windows have windowKinds = userKind (8) */
- windowKind = ((WindowPeek) window)->windowKind;
- return (windowKind = userKind);
- }
- } /*IsAppWindow*/
-
- Boolean IsDAWindow(window)
- WindowPtr window;
- {
- if ( window == nil )
- return false;
- else /* DA windows have -'ve windowKinds */
- return ((WindowPeek) window)->windowKind < 0;
- } /*IsDAWindow*/
-
- #pragma segment Initialize
- Boolean TrapAvailable(tNumber,tType)
- short tNumber;
- TrapType tType;
- {
- if ( ( tType == ToolTrap ) &&
- ( gMac.machineType > envMachUnknown ) &&
- ( gMac.machineType < envMacII ) ) {
- tNumber = tNumber & 0x03FF;
- if ( tNumber > 0x01FF )
- tNumber = _Unimplemented;
- }
- return NGetTrapAddress(tNumber, tType) != GetTrapAddress(_Unimplemented);
- } /*TrapAvailable*/
-
- #pragma segment Main
- void AlertUser(error)
- short error;
- {
- short itemHit;
- Str255 message;
-
- SetCursor(&qd.arrow);
- GetIndString(message, kErrStrings, error);
- ParamText(message, "", "", "");
- itemHit = Alert(rUserAlert, nil);
- } /* AlertUser */
-